import commonMixins from 'data-room-ui/js/mixins/commonMixins';
import linkageMixins from 'data-room-ui/js/mixins/linkageMixins';
import { mapState } from 'vuex';
export default {
  inject: {
    rootVm: {
      default: null,
    },
    interaction: {
      default: {},
    },
  },
  // 定时刷新需要
  mixins: [commonMixins, linkageMixins],
  methods: {
    watchShake(callback, time = 300, prefix = 'tm') {
      if (!time) {
        callback && callback();
      } else {
        const code = prefix + this.config.code;
        window[code] && clearTimeout(window[code]);
        window[code] = setTimeout(() => {
          callback && callback();
        }, time);
      }
    },
    // 定时刷新需要
    dataFormatting(config, data) {
      config.option.data = data.data;
      return config;
    },
  },
  computed: {
    isPreview() {
      return (
        this.$route?.path === window?.BS_CONFIG?.routers?.previewUrl ||
        this.$route?.path === '/big-screen/preview'
      );
    },
    ...mapState({
      fitStatus(state) {
        return this.rootVm ? this.rootVm.fitStatus : state.bigScreen.fitStatus;
      },

      chartList(state) {
        return this.rootVm
          ? this.rootVm.pageInfo.chartList
          : state.bigScreen.pageInfo.chartList;
      },
      pageInfo(state) {
        return this.rootVm ? this.rootVm.pageInfo : state.bigScreen.pageInfo;
      },
    }),
  },
};
